<%@ page language="java" import="java.util.*" pageEncoding="Utf-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>车辆出租</title>
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
 <link rel="stylesheet" href="${ctx}/resources/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
<link rel="stylesheet" type="text/css" href="${ctx}/resources/easyui/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/resources/css/wu.css" />
<link rel="stylesheet" type="text/css" href="${ctx}/resources/css/icon.css" />
<script type="text/javascript" src="${ctx}/resources/js/jquery-1.8.0.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${ctx}/resources/easyui/datagrid-detailview.js"></script>
<script type="text/javascript" src="${ctx}/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="${ctx}/resources/zTree/js/jquery.ztree.core.js"></script>
</head>

<body class="easyui-layout">
	 
<!-- 查询条件开始 -->
<div class="easyui-panel" data-options="region:'north',split:true,title:'查询条件',iconCls:'icon-search'" 
		style="width:100%;text-align: center;height: 100px;padding: 15px">
        <input class="easyui-searchbox" id="searchboxvalue" data-options="prompt:'请输入客户身份证号',searcher:doSearch" style="width:50%;">
	</div>
	<!-- 查询条件结束 -->
	 <div style="height: 2px"></div>
	 <!-- 数据表格开始 -->
	 <div id="content" class="easyui-penal" data-options="region:'center',border:false">
    <table id="table" class="easyui-datagrid" style="width:100%;height:300px">
    </table>
	 </div>
	<div id="tb">
	<a href="javascript:void(0)" class="easyui-linkbutton" id="addCar" data-options="iconCls:'icon-add',plain:true">车辆出租</a>
	</div>
	<!-- 数据表格结束  -->
	
	
    
	<!-- 添加和修改车辆出租单的弹出层 结束-->
<div id="dlg" class="easyui-dialog" style="width:500px" data-options="closed:true,modal:true,border:'thin',buttons:'#dlg-buttons'">
        <form id="fm" method="post" novalidate style="margin:0;padding:20px 50px">
            <div style="margin-bottom:10px">
                <input name="rentid" id="rentid" class="easyui-textbox" required="true" label="出租单号:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="identity" id="identity" class="easyui-textbox" required="true" label="身份证号:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="carnumber" id="carnumber"  class="easyui-textbox" required="true" label="出租车牌:" style="width:100%">
            </div>
            <div style="margin-bottom:10px">
                <input name="price" class="easyui-textbox" required="true"  label="出租价格:" style="width:100%">
            </div>
             <div style="margin-bottom:10px">
                <input name="begindate" class="easyui-datebox" required="true"  label="起租时间:" style="width:100%">
            </div>
             <div style="margin-bottom:10px">
                <input name="returndate" class="easyui-datebox" required="true"  label="还车时间:" style="width:100%">
            </div>
             <div style="margin-bottom:10px">
             <label class="textbox-label">
        				出租状态:
        			</label>
           			 <input class="easyui-radiobutton" name="rentflag" value="0">&nbsp;&nbsp;未归还&nbsp;&nbsp;&nbsp;&nbsp;
           			 <input class="easyui-radiobutton" name="rentflag" value="1">&nbsp;&nbsp;已归还
            </div>
             <div style="margin-bottom:10px">
                <input name="opername" id="opername"  class="easyui-textbox" required="true"  label="操作员:" style="width:100%">
            </div>
        </form>
    </div>
<div id="dlg-buttons">
        <a href="javascript:void(0)" class="easyui-linkbutton c6" iconCls="icon-ok" onclick="saveRent()" style="width:90px">保存</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dlg').dialog('close')" style="width:90px">取消</a>
    </div>
	<script type="text/javascript">
	$(function(){
		$("#content").hide(); //为查询时隐藏查询结果文本框
	})
	 
		//查询
		function doSearch(value){
			$.post("${ctx}/rent/loadCustomerByIdentity.action",{identity:value},function(obj){
				if(obj===""){
					$("#content").hide();
					$.messager.show({
						title:'提示',
						msg:'客户身份证号输入不正确'
					});
				}else{
					$("#content").show();  //身份证有效，显示查询结果
					initTable();
				}
			})			
		};
		function initTable(){
			//加载表格数据
			$("#table").datagrid({
				title:'车辆列表',
				singleSelect:true,
				collapsible:true,
		        fitColumns:true,
		        pagination:true,
		        rownumbers:true,
		        toolbar:'#tb',
		        url:'${ctx}/car/loadAllCar.action?isrenting=0',
		        columns:[[
		                  {field:'carnumber',title:'身份证号',align:'center',width:100},
		                  {field:'cartype',title:'车辆姓名',align:'center',width:100},
		                  {field:'color',title:'车辆地址',align:'center',width:100},
		                  {field:'isrenting',title:'车辆性别',align:'center',width:100,formatter:function(value){
		                	  if(value==0){
		                 		 return "<font color=red>未出租</font>"; 
		                 	  }else{
		                 		  return "<font color=green>已出租</font>"; 
		                 	  }
		                  }},
		                  {field:'price',title:'车辆电话',align:'center',width:100},
		                  {field:'rentprice',title:'车辆电话',align:'center',width:100},
		                  {field:'deposit',title:'车辆电话',align:'center',width:100},
		                  {field:'description',title:'车辆电话',align:'center',width:100}
		              ]],
			 	view: detailview,
		     	detailFormatter:function(index,row){
		         	return "<img width=150 height=100 title=车辆图片 src='"+row.carimg+"'/>" ;
		    	 }
			});
		}
		//打开添加用户的弹出层
		
		$("#addCar").click(function(){
			var row=$("#table").datagrid("getSelected");
			if(row){
			$("#dlg").dialog("open").dialog('setTitle','车辆出租');
			$("#fm").form("clear");//清空表格
			//先将选中行的数据提交给后台，在后台添加初始化信息完善选中行的添加表单信息
			//再用form的load方法，对后台返回的对象，进行数据装载
			$.post("${ctx}/rent/initRentForm.action",{
				identity:$("#searchboxvalue").val(),
				carnumber:row.carnumber,
				price:row.rentprice
			},function(obj){
				$("#fm").form("load",obj);
			},"json");                         //注意返回的数据为json类型
			$("#rentid").textbox({readonly:true});
			$("#identity").textbox({readonly:true});
			$("#carnumber").textbox({readonly:true});
			$("#opername").textbox({readonly:true});
			}else{
				$.messager.show({
					title:'提示',
					msg:'请选中操作行'
				});
			}
			//设置默认图片地址
		});
		function saveRent(){
			$.messager.progress();	// 显示进度条
			$('#fm').form('submit', {
				url: "${ctx}/rent/addRent.action",                                  //数据提交地址  user/addCar.action
				onSubmit: function(){
					var isValid = $(this).form('validate');//对表单里面的required:true和vailType的数据进行验证
					if (!isValid){
						$.messager.progress('close');	    // 如果验证失败关闭进度条
					}
					return isValid;	                  //返回验证结果
				},
				success: function(obj){               //如果提交成功之后回调的方法
					$.messager.progress('close');	  // 关闭进度条
                    var result = eval('('+obj+')');    //把obj的josn字符串转成js认识的json对象
					$.messager.show({
						title:'提示',
						msg:result.msg
					});
					$("#table").datagrid("reload");    //刷新数据表格
					$("#dlg").dialog("close");         //关闭弹出层
				}
			});
		}
	</script>
</body>
</html>
